package com.sky.controller.user;

import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.PageResultForHistoryOrder;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: Sabrina
 * @Date:2025/06/13/20:27
 * @Description:
 */
@Slf4j
@RestController
@Api(tags = "C端-订单接口")
@RequestMapping("/user/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result submit(@RequestBody OrdersSubmitDTO dto){
        log.info("用户下单：{}", dto);
        OrderSubmitVO vo = orderService.submit(dto);
        return Result.success(vo);
    }

    @GetMapping("/reminder/{id}")
    @ApiOperation("催单")
    public Result reminder(@PathVariable Integer id){
        log.info("催单 :{}", id);
        orderService.reminder(id);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result oneMoreOrder(@PathVariable Long id){
        log.info("再来一单 :{}", id);
        orderService.oneMoreOrder(id);
        return Result.success();
    }

    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable Integer id){
        log.info("取消订单 :{}", id);
        orderService.cancel(id);
        return Result.success();
    }

    @PutMapping("/payment")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付: {}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单:{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情(查一条)")
    public Result getOrderById(@PathVariable Integer id){
        log.info("查询订单详情(查一条) :{}", id);
        OrderVO orderVO = orderService.getOrderById(id);
        return Result.success(orderVO);
    }

    @GetMapping("/historyOrders")
    @ApiOperation("查询订单详情(查多条)")
    public Result getOrders(@RequestParam(defaultValue = "1")Integer page,
                            @RequestParam(defaultValue = "5")Integer pageSize,
                            Integer status){
        log.info("查询订单详情(查多条) :{},{},{}",page,pageSize,status);
        PageResult pageResult = orderService.getOrders(page,pageSize,status);
        /*PageResultForHistoryOrder pageResultForHistoryOrder = new PageResultForHistoryOrder();
        BeanUtils.copyProperties(pageResult,pageResultForHistoryOrder);
        pageResultForHistoryOrder.setRecentOrdersList(pageResult.getRecords());*/
        return Result.success(pageResult);
    }



}
